package com.huishi.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @TableName data_x_task_info
 */
@TableName(value = "data_x_task_info")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataXTaskInfo implements Serializable {
    /**
     *
     */
    @TableId(value = "id")
    private Long id;

    /**
     * 用户id
     */
    @TableField(value = "user_id")
    private Long userId;

    /**
     * 任务名称
     */
    @TableField(value = "task_name")
    private String taskName;

    /**
     * 表名
     */
    @TableField(value = "table_name")
    private String tableName;

    /**
     * 时间戳字段名
     */
    @TableField(value = "timestamp_column")
    private String timestampColumn;

    /**
     * 写入模式
     * insert
     * replace
     * update
     */
    @TableField(value = "writeMode")
    private String writemode;

    /**
     * 首次执行时间
     */
    @TableField(value = "first_execute_time")
    private Date firstExecuteTime;

    /**
     * 执行间隔时间
     */
    @TableField(value = "execute_interval")
    private Integer executeInterval;

    /**
     * 执行间隔时间单位
     * 012345
     */
    @TableField(value = "execute_interval_unit")
    private Integer executeIntervalUnit;

    /**
     * 最后一次执行时间
     */
    @TableField(value = "last_execute_time")
    private Date lastExecuteTime;

    /**
     * 执行状态：
     * 1 - 完成
     * 2 - 未完成
     */
    @TableField(value = "state")
    private Integer state;

    /**
     * 任务类型：
     * 1 - 全量
     * 2 - 增量
     */
    @TableField(value = "task_type")
    private Integer taskType;

    /**
     * 源数据源id
     */
    @TableField(value = "source_id")
    private Long sourceId;

    /**
     * 目标数据源id
     */
    @TableField(value = "target_id")
    private Long targetId;

    /**
     *
     */
    @TableField(value = "create_time")
    private Date createTime;

    /**
     *
     */
    @TableField(value = "update_time")
    private Date updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    // 增量任务
    public DataXTaskInfo(DataSource source, DataSource target, List<String> tables, Integer taskType, String timestampColumn, String writemode, Date firstExecuteTime, Integer executeInterval, Integer executeIntervalUnit) {
        this.sourceId = source.getId();
        this.targetId = target.getId();
        this.taskType = taskType;
        this.tableName = tables.toString();
        this.timestampColumn = timestampColumn;
        this.writemode = writemode;
        this.firstExecuteTime = firstExecuteTime;
        this.executeInterval = executeInterval;
        this.executeIntervalUnit = executeIntervalUnit;
        this.createTime = new Date();
        this.updateTime = new Date();
    }

    // 全量任务
    public DataXTaskInfo(Long id, DataSource source, DataSource target, List<String> tables, Integer taskType) {
        this.id = id;
        this.sourceId = source.getId();
        this.targetId = target.getId();
        this.taskType = taskType;
        this.tableName = tables.toString();
        this.createTime = new Date();
        this.updateTime = new Date();
    }
}